<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>

</body>
<script>
    class Point {
        constructor(x, y) {
            this.x = x;
            this.y = y;
        }

        // 私有属性/方法
        // 1.  只能在class内部使用,class外无法使用
        // 2.  私有属性/方法  无法被继承 (私有属性只能在定义它的 class 里面使用)
        #a = 1;
        #addA() {
            this.#a ++;
        }

        sayA() {

            this.#addA();

            return this.#a;
        }

        toString() {
            return `(${this.x},${this.y})`;
        }
    }

    var p = new Point(1, 2);
    console.log(p);

    // console.log(p.#a);
    var res = p.sayA();
    console.log(res);


    class Point3D extends Point {
        constructor(x, y, z) {
            super(x, y);
            this.z = z;
        }

        sayA() {
            // console.log(this.#a);
        }

        toString() {
            return `(${this.x},${this.y},,${this.z})`;
        }
    }

    var p1 = new Point3D(1, 2, 3);
    console.log(p1);



    function count(callback) {
        var a = 0;
        return function (...list) { // Rest参数 将所有参数整合到数组中
            a++;
            if (a % 10 == 0) {
                callback.apply(this, list);
            }
        }
    }

    var obj = {
        a: 1,
        b: 2,
        sum: count(function () {
            console.log(this);
            console.log(this.a, this.b);
        })
    }
    obj.sum();
    obj.sum();
    obj.sum();
    obj.sum();
    obj.sum();
    obj.sum();
    obj.sum();
    obj.sum();
    obj.sum();
    obj.sum();




</script>

</html>